package cn.iocoder.yudao.module.dlbz.service.companypayrecord;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.dlbz.controller.admin.companypayrecord.vo.*;
import cn.iocoder.yudao.module.dlbz.dal.dataobject.companypayrecord.CompanyPayRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.dlbz.dal.mysql.companypayrecord.CompanyPayRecordMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.dlbz.enums.ErrorCodeConstants.*;

/**
 * 企业支付记录 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class CompanyPayRecordServiceImpl implements CompanyPayRecordService {

    @Resource
    private CompanyPayRecordMapper companyPayRecordMapper;

    @Override
    public Long createCompanyPayRecord(CompanyPayRecordSaveReqVO createReqVO) {
        // 插入
        CompanyPayRecordDO companyPayRecord = BeanUtils.toBean(createReqVO, CompanyPayRecordDO.class);
        companyPayRecordMapper.insert(companyPayRecord);
        // 返回
        return companyPayRecord.getId();
    }

    @Override
    public void updateCompanyPayRecord(CompanyPayRecordSaveReqVO updateReqVO) {
        // 校验存在
        validateCompanyPayRecordExists(updateReqVO.getId());
        // 更新
        CompanyPayRecordDO updateObj = BeanUtils.toBean(updateReqVO, CompanyPayRecordDO.class);
        companyPayRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteCompanyPayRecord(Long id) {
        // 校验存在
        validateCompanyPayRecordExists(id);
        // 删除
        companyPayRecordMapper.deleteById(id);
    }

    private void validateCompanyPayRecordExists(Long id) {
        if (companyPayRecordMapper.selectById(id) == null) {
            throw exception(COMPANY_PAY_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public CompanyPayRecordDO getCompanyPayRecord(Long id) {
        return companyPayRecordMapper.selectById(id);
    }

    @Override
    public PageResult<CompanyPayRecordDO> getCompanyPayRecordPage(CompanyPayRecordPageReqVO pageReqVO) {
        return companyPayRecordMapper.selectPage(pageReqVO);
    }

}